<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>SUOYUEの交流区</title>

  <link rel="shortcut icon" th:href="@{/images/favicon.ico}" />
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/semantic-ui/2.2.4/semantic.min.css">
  <link rel="stylesheet" href="../static/css/me.css" th:href="@{/css/me.css}">
</head>
<body>

<!--导航栏-->
<nav class="ui inverted gird-header" >
    <div class="ui container">
        <div class="ui inverted secondary stackable menu">
            <h2 class="ui olive header item" style="font-family: STSong">SUOYUE</h2>
            <a href="#" th:href="@{/}" class="m-item item m-mobile-hide"><i class="home icon"></i><span th:text="#{index.home}">首页</span></a>
            <a href="#" th:href="@{/hotArticle}" class="m-item item m-mobile-hide"><i class="clone outline icon"></i><span th:text="#{index.hotArticle}">热门文章</span></a>
            <a href="#" th:href="@{/newArticle}" class="m-item item m-mobile-hide"><i class="clock icon"></i><span th:text="#{index.time}">时间轴</span></a>
            <a href="#" th:href="@{/activeUser}" class="m-item item m-mobile-hide"><i class="clone outline icon"></i><span th:text="#{index.user}">活跃好友</span></a>
            <a href="#" th:href="@{/message}" class="active m-item item m-mobile-hide"><i class="book icon"></i><span th:text="#{index.messages}">留言板</span></a>
<!--            <a href="#" th:href="@{/echarts}" class="m-item item m-mobile-hide"><i class="clone outline icon"></i><span th:text="#{index.map}">疫情地图</span></a>-->
            <!--  创作中心  -->
            <h5 class="m-item item m-mobile-hide" style="font-family: STSong"><a href="#" th:href="@{/user/index}" class="ui inverted green rounded button" ><i class="edit icon"></i>创作中心</a></h5>

            <!--  用户头像  -->
            <div class="left m-item m-mobile-hide menu" th:if="${session.user}">
                <div class="ui dropdown item">
                    <div class="text">
                        <img class="ui avatar image" src="../../static/images/me.jpg" th:src="${session.user.avatar}">
                    </div>
                    <i class="dropdown icon"></i>
                    <div class="menu">
                        <a href="" th:href="@{/logout}" class="item">注销</a>
                    </div>
                </div>
            </div>
            <!--  搜索栏  -->
            <div class="right m-item item m-mobile-hide">
                <form name="search" action="#" th:action="@{/search}" method="post" target="_blank">
                    <div class="ui icon transparent input m-margin-tb-tiny" style="color: white">
                        <input style="color: white" type="text" name="query" placeholder="Search....">
                        <i onclick="document.forms['search'].submit()" class="search link icon"></i>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <!--手机端收起导航栏-->
    <a href="#" class="ui menu toggle black icon button m-right-top m-mobile-show">
        <i class="sidebar icon"></i>
    </a>
</nav>

<!--顶部图片-->
<div class="m-bg-type_outer" style="width: 100%;height: 36%">
  <img src="../static/images/messagebg.jpg" th:src="@{/images/messagebg.jpg}" alt="" class="ui m-bg image" style="width: 100%;height: 100%">
  <div class="m-bg-class_cover">
    <div class="ui container" style="position: relative ;bottom: -590px;">
      <div class="m-font-size-title m-right-bottom" align="center" style="font-family:'STXingkai'">留言板</div>
      <div class="m-font-size-text-init-title m-margin-top" align="center">虽然只是短暂的擦身，相遇与分别，尽管如此，我却仍然想珍惜这所有的一切</div>
    </div>
  </div>
</div>


<!--中间内容-->
<div id="waypoint" class="m-padded-tb animated fadeIn">
  <div class="ui container m-opacity box-shadow-max">
      <!--发表评论-->
      <div id="message-form" class="ui form">
          <input type="hidden" name="parentMessage.id" value="-1">
          <!--留言信息-->
          <div class="field">
              <textarea name="content" placeholder="请先登录再发表言论..."></textarea>
          </div>
          <div class="ui grid">
              <!--输入姓名-->
              <div class="five wide column">
                  <div class="field m-mobile-wide m-margin-bottom-small">
                      <div class="ui left icon input">
                          <i class="user icon"></i>
                          <input type="text" disabled="true" name="nickname" placeholder="称呼" th:value="${session.user}!=null ? ${session.user.username}">
                      </div>
                  </div>
              </div>

              <!--输入邮箱-->
              <div class="five wide column">
                  <div class="field m-mobile-wide m-margin-bottom-small">
                      <div class="ui left icon input">
                          <i class="mail icon"></i>
                          <input type="text" disabled="true" name="email" placeholder="Email" th:value="${session.user}!=null ? ${session.user.email}">
                      </div>
                  </div>
              </div>

              <div class="right aligned six wide column">
                  <div class="field m-mobile-wide m-margin-bottom-small">
                      <button id="messagepost-btn" type="button" class="ui teal button m-mobile-wide"><i class="edit icon"></i>发布</button>
                  </div>
              </div>

          </div>
      </div>
      <!--留言区列表-->
      <div class="ui bottom attached m-margin-top">
          <div id="message-container" class="ui teal segment">
              <!--定义messageList片段，控制层返回-->
              <div th:fragment="messageList">
                  <div class="ui threaded comments" style="max-width: 100%;">
                      <h3 class="ui dividing header">留言</h3>
                      <div class="comment" th:each="comment: ${messages}">
                          <a class="avatar">
                              <img src="../static/images/avatar.jpg" th:src="@{${comment.avatar}}">
                          </a>
                          <div class="content">
                              <a class="author">
                                  <span th:text="${comment.nickname}">Matt</span>
                                  <div class="ui mini basic teal left pointing label m-padded-mini" th:if="${comment.adminMessage}">管理员</div>
                              </a>
                              <div class="metadata">
                                  <span class="date" th:text="${#dates.format(comment.createTime,'yyyy-MM-dd HH:mm')}">今天下午 5:42</span>
                              </div>
                              <div class="text" th:text="${comment.content}">太赞了！ </div>
                              <div class="actions">
                                  <a class="reply" data-messageid="1" th:attr="data-messageid=${comment.id},data-messagenickname=${comment.nickname}" data-messagenickname="Matt" onclick="reply(this)">回复</a>
                                  <a class="delete" href="#" th:href="@{/messages/{id}/delete(id=${comment.id})}" onclick="return confirm('确定删除该留言？三思啊! 删了可就没了！（也不是谁的留言都能删哦!）')" th:if="${session.user}">删除</a>
                              </div>
                          </div>
                          <!--子集留言-->
                          <div class="comments" th:if="${#arrays.length(comment.replyMessages)}>0">
                              <div class="comment" th:each="reply: ${comment.replyMessages}">
                                  <a class="avatar">
                                      <img src="../static/images/avatar.jpg" th:src="@{${reply.avatar}}">
                                  </a>
                                  <div class="content">
                                      <a class="author">
                                          <span th:text="${reply.nickname}">小红</span>
                                          <div class="ui mini basic teal left pointing label m-padded-mini" th:if="${reply.adminMessage}">管理员</div>
                                          &nbsp;<span class="m-teal" th:text="|@ ${reply.parentNickname}">@ 小白</span>
                                      </a>
                                      <div class="metadata">
                                          <span class="date" th:text="${#dates.format(reply.createTime,'yyyy-MM-dd HH:mm')}">今天下午 5:42</span>
                                      </div>
                                      <div class="text" th:text="${reply.content}">太赞了！ </div>
                                      <div class="actions">
                                          <a class="reply" data-messageid="1" data-messagenickname="Matt" th:attr="data-messageid=${reply.id},data-messagenickname=${reply.nickname}" onclick="reply(this)">回复</a>
                                          <a class="delete" href="#" th:href="@{/messages/{id}/delete(id=${reply.id})}" onclick="return confirm('确定删除该留言？三思啊! 删了可就没了！（也不是谁的留言都能删哦!）')" th:if="${session.user}">删除</a>
                                      </div>
                                  </div>
                              </div>
                          </div>
                      </div>

                  </div>
              </div>
          </div>
      </div>

    <br>
    <br>
    <br>

  </div>
</div>

<br>
<br>
<br>

<!--右下角-侧边栏-->
<div id="toolbar" class="m-padded m-fixed m-right-bottom" style="display: none">
    <div class="ui vertical icon buttons ">
        <div id="toTop-button" class="ui icon button" ><i class="chevron up icon"></i></div>
    </div>
</div>

<!--底部栏-->
<footer class="ui inverted vertical segment m-padded-tb-massive m-opacity" th:replace="_fragments :: footer">

</footer>


<script src="../static/js/jquery.min.js" th:src="@{/js/jquery.min.js}"></script>
<script src="../static/lib/Semantic-UI/semantic.min.js" th:src="@{/lib/Semantic-UI/semantic.min.js}"></script>
<!-- 引入安全规范，禁用F12... -->
<script src="../static/js/safe.js" th:src="@{/js/safe.js}"></script>
<script src="//cdn.jsdelivr.net/npm/jquery.scrollto@2.1.2/jquery.scrollTo.min.js"></script>
<script src="../static/lib/waypoints/jquery.waypoints.min.js" th:src="@{/lib/waypoints/jquery.waypoints.min.js}"></script>

<script>

    $('.menu.toggle').click(function () {
        $('.m-item').toggleClass('m-mobile-hide');
    });


    $('.ui.dropdown').dropdown({
        on : 'hover'
    });

    //评论表单验证
    $('.ui.form').form({
        fields: {
            title: {
                identifier: 'content',
                rules: [{
                    type: 'empty',
                    prompt: '请输入评论内容'
                }
                ]
            },
            // content: {
            //     identifier: 'nickname',
            //     rules: [{
            //         type: 'empty',
            //         prompt: '请输入你的大名'
            //     }]
            // },
            // type: {
            //     identifier: 'email',
            //     rules: [{
            //         type: 'email',
            //         prompt: '请填写正确的邮箱地址'
            //     }]
            // }
        }
    });

    // 初始化加载评论区
    $(function () {
        $("#message-container").load(/*[[@{/messagecomment}]]*/"messagecomment");
    });

    // 校验信息
    $('#messagepost-btn').click(function () {
        var boo = $('.ui.form').form('validate form');
        if (boo) {
            console.log('校验成功');
            postData();
        } else {
            console.log('校验失败');
        }
    });

    //发送请求给后端
    function postData() {
        $("#message-container").load(/*[[@{/messages}]]*/"",{
            "parentMessage.id" : $("[name='parentMessage.id']").val(),
            "nickname": $("[name='nickname']").val(),
            "email"   : $("[name='email']").val(),
            "content" : $("[name='content']").val()
        },function (responseTxt, statusTxt, xhr) {
            $(window).scrollTo($('#message-container'),500);
            clearContent();
        });
    }

    // 清除表单
    function clearContent() {
        // $("[name='nickname']").val('');
        // $("[name='email']").val('');
        $("[name='content']").val('');
        $("[name='parentMessage.id']").val(-1);
        $("[name='content']").attr("placeholder", "请输入评论信息...");
    }

    function reply(obj) {
        var messageId = $(obj).data('messageid');
        var messageNickname = $(obj).data('messagenickname');
        $("[name='content']").attr("placeholder", "@"+messageNickname).focus();
        $("[name='parentMessage.id']").val(messageId);
        $(window).scrollTo(0,500);
    }


    //消息提示关闭初始化
    $('.message .close')
        .on('click', function () {
            $(this)
                .closest('.message')
                .transition('fade');
        });

    //右下角点击滚上去事件
    $('#toTop-button').click(function () {
        $(window).scrollTo(0,500);
    });
    //滚动侦测
    var waypoint = new Waypoint({
        element: document.getElementById('waypoint'),
        handler: function(direction) {
            if (direction == 'down') {
                $('#toolbar').show(100);
            } else {
                $('#toolbar').hide(500);
            }
            console.log('Scrolled to waypoint!  ' + direction);
        }
    })

</script>


<!--看板娘-->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome/css/font-awesome.min.css">
<script src="https://cdn.jsdelivr.net/gh/stevenjoezhang/live2d-widget/autoload.js"></script>
<!--看板娘-自定义-->
<div id="waifu" class="cartoon">
    <div id="waifu-tips" class="cartoonText">好久不见，日子过得好快呢……</div>
    <canvas id="live2d" width="800" height="800" class="cartoonCan"></canvas>
    <div id="waifu-tool">
        <span class="fa fa-lg fa-comment"></span>
        <span class="fa fa-lg fa-paper-plane"></span>
        <span class="fa fa-lg fa-user-circle"></span>
        <span class="fa fa-lg fa-street-view"></span>
        <span class="fa fa-lg fa-camera-retro"></span>
        <span class="fa fa-lg fa-info-circle"></span>
        <span class="fa fa-lg fa-times"></span>
    </div>
</div>

</body>
</html>